#include <iostream>
#include <vector>
using std::cout;
using std::endl;
using std::vector;

class Point{
public:
    Point(int x = 0,int y = 0)
    : _ix(x)
    , _iy(y)
    {
        cout << "Point(int,int)" << endl;
    }

    Point(const Point & rhs)
    : _ix(rhs._ix)
    , _iy(rhs._iy)
    {
        cout << "Point(const Point &)" << endl;
    }

    ~Point(){
        cout << "~Point()" << endl;
    }

    void print() const{
        cout << "(" << _ix
            << "," << _iy
            << ")" << endl;
    }
private:
    int _ix;
    int _iy;
};

void test0(){
    //无参构造创建出来的vector是空的vector
    //直接进行push_back会有动态扩容情况
    //如果先准备好空间，就不会动态扩容
    vector<Point> vec;
    vec.reserve(10);
    vec.push_back(Point(1,2));//每次将临时对象的副本作为容器元素保存
    vec.push_back(Point(3,5));
    vec.push_back(Point(4,7));
    vec.push_back(Point(4,7));
}

void test1(){
    vector<Point> nums;
    //保存5个Point对象（该类型的默认值 —— 无参构造初始化）
    vector<Point> nums2(5);
    /* for(auto & ele : nums2){ */
    /*     ele.print(); */
    /* } */

    //保存3个（4,0）
    vector<Point> nums3(3,4);
    for(auto & ele : nums3){
        ele.print();
    }
    
    //保存了（3,0）（4,0）
    vector<Point> nums4{3,4};
    for(auto & ele : nums4){
        ele.print();
    }

    //灵活指定元素内容
    vector<Point> nums5{{2,6},{8,9}};
    for(auto & ele : nums5){
        ele.print();
    }
}

void test2(){
    Point pt(1,2);
    Point pt2(4,8);
    vector<Point> vec{pt,pt2};
    cout << &pt << endl;
    cout << &vec[0] << endl;

    vector<Point> vec2{{2,6},{8,9}};
    for(auto & ele : vec2){
        ele.print();
    }

}
  
int main(void){
    test0();
    return 0;
}

